import {
  AuditStatus,
  ContractStatus,
  Source,
} from '@/api/audit/auth/model/authorModel'
import {
  MaterialType,
  MaterialSecType,
} from '@/components/ItemList/MaterialList/types'
import { getRandomIntInclusive } from '@/utils/numberHelper'

export default function useFormat() {
  /**
   * 格式化素材类型
   */
  const formatType = (type: MaterialType, itype: MaterialSecType) => {
    const typeMap: { [value in MaterialType]: string } = {
      [MaterialType.IMAGE]: '图片',
      [MaterialType.VIDEO]: '视频',
      [MaterialType.MUSIC]: '音乐',
      [MaterialType.FONT]: '字体',
    }

    const itypeMap: { [value in MaterialSecType]: string } = {
      [MaterialSecType.NONE]: '无',
      [MaterialSecType.PHOTOGRAPHY]: '摄影图',
      [MaterialSecType.AVOID_CUTOUT]: '免扣',
      [MaterialSecType.VECTORGRAPH]: '设计矢量图',
    }

    return `${typeMap[type] || '未知'}-${itypeMap[itype] || '未知'}`
  }

  const fromatContractStatus = (type: ContractStatus) => {
    const contractType: { [value in ContractStatus]: JSX.Element } = {
      [ContractStatus.NORMAL]: <a-badge status="success" text="已签约" />,
      [ContractStatus.UNCONTRACT]: <a-badge status="default" text="已解约" />,
    }
    return contractType[type]
  }
  const fromatAuthAuditStatus = (type: AuditStatus) => {
    const contractType: { [value in AuditStatus]: JSX.Element } = {
      [AuditStatus.WAIT]: <a-badge status="processing" text="待审" />,
      [AuditStatus.ACCESS]: <a-badge status="success" text="审核通过" />,
      [AuditStatus.UNACCESS]: <a-badge status="error" text="审核不通过" />,
    }
    return contractType[type]
  }
  const fromatAuthSource = (type: Source) => {
    const contractType: { [value in Source]: string } = {
      [Source.PLUS]: 'PLUS',
      [Source.DP]: 'DP',
      [Source.BEST_IMG]: '优图佳视',
      [Source.OPEN_PIECE]: '开篇',
    }
    return contractType[type]
  }

  const formatTag = (tags: string[], type: 'tag' | 'atlas' | 'categories') => {
    const colorList = [
      'pink',
      'red',
      'orange',
      'green',
      'cyan',
      'blue',
      'purple',
    ]
    if (tags.length <= 0) {
      return '暂无'
    }
    if (type === 'atlas') {
      return tags.map((item) => <a-tag color="#108ee9">{item}</a-tag>)
    }
    if (type === 'categories') {
      return tags.map((item) => <a-tag color="#2db7f5">{item}</a-tag>)
    }
    if (type === 'tag') {
      return tags.map((item) => (
        <a-tag color={colorList[getRandomIntInclusive(0, 6)]}>{item}</a-tag>
      ))
    }
    return tags.map((item) => <a-tag>{item}</a-tag>)
  }
  return {
    formatTag,
    formatType,
    fromatContractStatus,
    fromatAuthAuditStatus,
    fromatAuthSource,
  }
}
